<% content_for :navigation do %>
  <% render :layout => "layouts/main_navigation" do %>
    <%= render :partial => "layouts/navigation/devices_item", :locals => {:classes => "tab-separator", :house => @house, :user => @user} %>
    <%= render :partial => "layouts/navigation/add_edit_discover_item", :locals => {:classes => "selected tab-separator", :house => @house, :user => @user} %>
  <% end %>
<% end %>

    <%= javascript_include_tag "devices", "jquery.typeWatch"  %>


<%= content_tag :h1, t(:add_edit_discover, :scope => [:house, :devices]) %>
<%= content_tag :p, t(:add_edit_discover, :scope => [:house, :devices, :hints], :discover_button => "\"#{t(:label, :scope => [:device, :discover])}\"") %>

<% form_for @house, :url => user_house_devices_url(@user, @house),
    :html => {:method => :post, :class => "basic-form rounded device-form"} do |house_form| %>

    <% content_for :javascript do %>
      $(document).ready(function(){
        $(".search-for-known-device").watchMeAjax({
      parent: false, url: "<%= know_user_house_devices_url %>?device_class=", ajax_only: true,
      captureLength : 1});
      });
      $(".add-house-device").live("click",function(){
        <%= "var device='#{generate_template(house_form, :devices, :partial => "devices/devices_rows_form")}'" %>

        var new_id = new Date().getTime();
        $("#devices_table > tbody").append(device.replace(/NEW_RECORD/g, new_id)).children("tr").last().highlightMe().
          find("input[type=text]").first().watchMeAjax({
      parent: false, url: "<%= know_user_house_devices_url %>?device_class=", ajax_only: true,
      captureLength : 1});

        $(".title-me").tipTip();
       
        return false;
      });

      $(".remove-new-device").live("click", function(){      
          if(confirm($(this).confirmPlz()))
  $(this).closest("tr").remove();
  
          return false;
      });

      $(".remove-existing-device").live("click", function(){
          if(confirm($(this).confirmPlz()))
          {
  $(this).closest("tr").find(".remove-device-hidden").val(1);  
  $(this).closest("tr").hide();
          }

          return false;
      });
    <% end %>

    <%= error_messages_for :house, :associations => :devices, :class => "alert red error rounded-8" %>

    <div id="devices_errors" style="display:none"></div>

    <%= render :partial => "devices_table_form", :locals => {:house => @house,
                    :devices => @devices,
                    :house_form => house_form} %>

    <%= awesome_submit_button t(:submit, :scope => :form), :tick %>
<% end %>

<% content_for :sidebar do %>
    <%= render :partial => "discover_sidebar", :locals =>{:user => @user, :house => @house} %>
    <%= render :partial => "add_edit_discover_help_sidebar" %>
<% end %>